Hello, |
Re: how to search for a file under a directory
|
Re: how to search for a file under a directory |
Re: how to search for a file under a directory Here is some old cob-web code, maybe you can make enough sense out of it.
//********************
void SearchDir(string NameDir, bool Recurse, Buffer &Results)
{ // display the folders and files in the directory
// Optionally Recurs through subfolders
// This function is RECURSION enabled
string NameFile
string NameFull
Stat stat
set (dbeStatus, "... '" NameDir "'")
g_NumFolders++
Results += "\n..." NameDir[g_OriginLen:]"\n"
// *** [1] Print the info of all SubFolders
for NameFile in directory NameDir do
{ if (NameFile[0:0] == ".") // skip the "." and ".." file names. No other name may begin with '.'
continue
if (NameFile == NameDir) // Don't recall why, but skip a file with exact name as Directory
continue
NameFull = NameDir "\\" NameFile
stat = create(NameFull)
// print "considering >" NameFull "<\n"
if (!null stat and directory(stat))
DisplayInfo(stat, true, NameDir, NameFile, Results)
if (!null stat) delete(stat)
}
// *** [2] Print the info of all Files
for NameFile in directory NameDir do
{ if (NameFile[0:0] == ".")
continue
if (NameFile == NameDir)
continue
g_NumFiles++
NameFull = NameDir "\\" NameFile
stat = create(NameFull)
if (!null stat and (regular(stat) or symbolic(stat)))
DisplayInfo(stat, false, NameDir, NameFile, Results)
if (!null stat) delete(stat)
}
// *** [3] Recurs through SubFolders
if (Recurse)
{ for NameFile in directory NameDir do
{ if (NameFile[0:0] == ".")
continue
NameFull = NameDir "\\" NameFile
stat = create(NameFull)
if (!null stat and directory(stat))
{ // print "*** NOT Doing >" NameFull "<\n"
SearchDir(NameFull, Recurse, Results) // ** RECURSION **
}
if (!null stat) delete(stat)
}
}
} // end SearchDir()
|
Re: how to search for a file under a directory llandale - Mon Nov 07 14:32:02 EST 2011 Here is some old cob-web code, maybe you can make enough sense out of it.
//********************
void SearchDir(string NameDir, bool Recurse, Buffer &Results)
{ // display the folders and files in the directory
// Optionally Recurs through subfolders
// This function is RECURSION enabled
string NameFile
string NameFull
Stat stat
set (dbeStatus, "... '" NameDir "'")
g_NumFolders++
Results += "\n..." NameDir[g_OriginLen:]"\n"
// *** [1] Print the info of all SubFolders
for NameFile in directory NameDir do
{ if (NameFile[0:0] == ".") // skip the "." and ".." file names. No other name may begin with '.'
continue
if (NameFile == NameDir) // Don't recall why, but skip a file with exact name as Directory
continue
NameFull = NameDir "\\" NameFile
stat = create(NameFull)
// print "considering >" NameFull "<\n"
if (!null stat and directory(stat))
DisplayInfo(stat, true, NameDir, NameFile, Results)
if (!null stat) delete(stat)
}
// *** [2] Print the info of all Files
for NameFile in directory NameDir do
{ if (NameFile[0:0] == ".")
continue
if (NameFile == NameDir)
continue
g_NumFiles++
NameFull = NameDir "\\" NameFile
stat = create(NameFull)
if (!null stat and (regular(stat) or symbolic(stat)))
DisplayInfo(stat, false, NameDir, NameFile, Results)
if (!null stat) delete(stat)
}
// *** [3] Recurs through SubFolders
if (Recurse)
{ for NameFile in directory NameDir do
{ if (NameFile[0:0] == ".")
continue
NameFull = NameDir "\\" NameFile
stat = create(NameFull)
if (!null stat and directory(stat))
{ // print "*** NOT Doing >" NameFull "<\n"
SearchDir(NameFull, Recurse, Results) // ** RECURSION **
}
if (!null stat) delete(stat)
}
}
} // end SearchDir()
|